.class final Lorg/jboss/netty/util/HashedWheelTimer$Worker;
.super Ljava/lang/Object;
.source "HashedWheelTimer.java"

# interfaces
.implements Ljava/lang/Runnable;


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lorg/jboss/netty/util/HashedWheelTimer;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x12
    name = "Worker"
.end annotation


# instance fields
.field private startTime:J

.field final synthetic this$0:Lorg/jboss/netty/util/HashedWheelTimer;

.field private tick:J


# direct methods
.method constructor <init>(Lorg/jboss/netty/util/HashedWheelTimer;)V
    .locals 0
    .parameter

    .prologue
    .line 360
    iput-object p1, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    .line 361
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 362
    return-void
.end method

.method private fetchExpiredTimeouts(Ljava/util/List;J)V
    .locals 5
    .parameter
    .parameter "deadline"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;",
            ">;J)V"
        }
    .end annotation

    .prologue
    .line 387
    .local p1, expiredTimeouts:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    iget-object v2, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v2, v2, Lorg/jboss/netty/util/HashedWheelTimer;->lock:Ljava/util/concurrent/locks/ReadWriteLock;

    invoke-interface {v2}, Ljava/util/concurrent/locks/ReadWriteLock;->writeLock()Ljava/util/concurrent/locks/Lock;

    move-result-object v2

    invoke-interface {v2}, Ljava/util/concurrent/locks/Lock;->lock()V

    .line 389
    :try_start_0
    iget-object v2, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget v3, v3, Lorg/jboss/netty/util/HashedWheelTimer;->wheelCursor:I

    add-int/lit8 v3, v3, 0x1

    iget-object v4, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget v4, v4, Lorg/jboss/netty/util/HashedWheelTimer;->mask:I

    and-int v1, v3, v4

    iput v1, v2, Lorg/jboss/netty/util/HashedWheelTimer;->wheelCursor:I

    .line 390
    .local v1, newWheelCursor:I
    iget-object v2, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v2, v2, Lorg/jboss/netty/util/HashedWheelTimer;->iterators:[Lorg/jboss/netty/util/internal/ReusableIterator;

    aget-object v0, v2, v1

    .line 391
    .local v0, i:Lorg/jboss/netty/util/internal/ReusableIterator;,"Lorg/jboss/netty/util/internal/ReusableIterator<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    invoke-direct {p0, p1, v0, p2, p3}, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->fetchExpiredTimeouts(Ljava/util/List;Lorg/jboss/netty/util/internal/ReusableIterator;J)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 393
    iget-object v2, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v2, v2, Lorg/jboss/netty/util/HashedWheelTimer;->lock:Ljava/util/concurrent/locks/ReadWriteLock;

    invoke-interface {v2}, Ljava/util/concurrent/locks/ReadWriteLock;->writeLock()Ljava/util/concurrent/locks/Lock;

    move-result-object v2

    invoke-interface {v2}, Ljava/util/concurrent/locks/Lock;->unlock()V

    .line 395
    return-void

    .line 393
    .end local v0           #i:Lorg/jboss/netty/util/internal/ReusableIterator;,"Lorg/jboss/netty/util/internal/ReusableIterator<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    .end local v1           #newWheelCursor:I
    :catchall_0
    move-exception v2

    iget-object v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v3, v3, Lorg/jboss/netty/util/HashedWheelTimer;->lock:Ljava/util/concurrent/locks/ReadWriteLock;

    invoke-interface {v3}, Ljava/util/concurrent/locks/ReadWriteLock;->writeLock()Ljava/util/concurrent/locks/Lock;

    move-result-object v3

    invoke-interface {v3}, Ljava/util/concurrent/locks/Lock;->unlock()V

    throw v2
.end method

.method private fetchExpiredTimeouts(Ljava/util/List;Lorg/jboss/netty/util/internal/ReusableIterator;J)V
    .locals 7
    .parameter
    .parameter
    .parameter "deadline"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;",
            ">;",
            "Lorg/jboss/netty/util/internal/ReusableIterator",
            "<",
            "Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;",
            ">;J)V"
        }
    .end annotation

    .prologue
    .line 401
    .local p1, expiredTimeouts:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    .local p2, i:Lorg/jboss/netty/util/internal/ReusableIterator;,"Lorg/jboss/netty/util/internal/ReusableIterator<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    const/4 v1, 0x0

    .line 402
    .local v1, slipped:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    invoke-interface {p2}, Lorg/jboss/netty/util/internal/ReusableIterator;->rewind()V

    .line 403
    :goto_0
    invoke-interface {p2}, Lorg/jboss/netty/util/internal/ReusableIterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_3

    .line 404
    invoke-interface {p2}, Lorg/jboss/netty/util/internal/ReusableIterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;

    .line 405
    .local v2, timeout:Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;
    iget-wide v3, v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->remainingRounds:J

    const-wide/16 v5, 0x0

    cmp-long v3, v3, v5

    if-gtz v3, :cond_2

    .line 406
    invoke-interface {p2}, Lorg/jboss/netty/util/internal/ReusableIterator;->remove()V

    .line 407
    iget-wide v3, v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->deadline:J

    cmp-long v3, v3, p3

    if-gtz v3, :cond_0

    .line 408
    invoke-interface {p1, v2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_0

    .line 414
    :cond_0
    if-nez v1, :cond_1

    .line 415
    new-instance v1, Ljava/util/ArrayList;

    .end local v1           #slipped:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    invoke-direct {v1}, Ljava/util/ArrayList;-><init>()V

    .line 417
    .restart local v1       #slipped:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    :cond_1
    invoke-interface {v1, v2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    goto :goto_0

    .line 420
    :cond_2
    iget-wide v3, v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->remainingRounds:J

    const-wide/16 v5, 0x1

    sub-long/2addr v3, v5

    iput-wide v3, v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->remainingRounds:J

    goto :goto_0

    .line 425
    .end local v2           #timeout:Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;
    :cond_3
    if-eqz v1, :cond_4

    .line 426
    invoke-interface {v1}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v0

    .local v0, i$:Ljava/util/Iterator;
    :goto_1
    invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_4

    invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;

    .line 427
    .restart local v2       #timeout:Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;
    iget-object v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-wide v4, v2, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->deadline:J

    sub-long/2addr v4, p3

    invoke-virtual {v3, v2, v4, v5}, Lorg/jboss/netty/util/HashedWheelTimer;->scheduleTimeout(Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;J)V

    goto :goto_1

    .line 430
    .end local v0           #i$:Ljava/util/Iterator;
    .end local v2           #timeout:Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;
    :cond_4
    return-void
.end method

.method private notifyExpiredTimeouts(Ljava/util/List;)V
    .locals 2
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;",
            ">;)V"
        }
    .end annotation

    .prologue
    .line 435
    .local p1, expiredTimeouts:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    invoke-interface {p1}, Ljava/util/List;->size()I

    move-result v1

    add-int/lit8 v0, v1, -0x1

    .local v0, i:I
    :goto_0
    if-ltz v0, :cond_0

    .line 436
    invoke-interface {p1, v0}, Ljava/util/List;->get(I)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;

    invoke-virtual {v1}, Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;->expire()V

    .line 435
    add-int/lit8 v0, v0, -0x1

    goto :goto_0

    .line 440
    :cond_0
    invoke-interface {p1}, Ljava/util/List;->clear()V

    .line 441
    return-void
.end method

.method private waitForNextTick()J
    .locals 13

    .prologue
    .line 444
    iget-wide v7, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->startTime:J

    iget-object v9, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-wide v9, v9, Lorg/jboss/netty/util/HashedWheelTimer;->tickDuration:J

    iget-wide v11, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->tick:J

    mul-long/2addr v9, v11

    add-long v2, v7, v9

    .line 447
    .local v2, deadline:J
    :cond_0
    :goto_0
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v0

    .line 448
    .local v0, currentTime:J
    iget-object v7, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-wide v7, v7, Lorg/jboss/netty/util/HashedWheelTimer;->tickDuration:J

    iget-wide v9, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->tick:J

    mul-long/2addr v7, v9

    iget-wide v9, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->startTime:J

    sub-long v9, v0, v9

    sub-long v5, v7, v9

    .line 450
    .local v5, sleepTime:J
    const-wide/16 v7, 0x0

    cmp-long v7, v5, v7

    if-gtz v7, :cond_1

    .line 464
    iget-wide v7, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->tick:J

    const-wide/16 v9, 0x1

    add-long/2addr v7, v9

    iput-wide v7, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->tick:J

    .line 465
    .end local v2           #deadline:J
    :goto_1
    return-wide v2

    .line 455
    .restart local v2       #deadline:J
    :cond_1
    :try_start_0
    invoke-static {v5, v6}, Ljava/lang/Thread;->sleep(J)V
    :try_end_0
    .catch Ljava/lang/InterruptedException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 456
    :catch_0
    move-exception v4

    .line 457
    .local v4, e:Ljava/lang/InterruptedException;
    iget-object v7, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v7, v7, Lorg/jboss/netty/util/HashedWheelTimer;->shutdown:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v7}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v7

    if-eqz v7, :cond_0

    .line 458
    const-wide/16 v2, -0x1

    goto :goto_1
.end method


# virtual methods
.method public run()V
    .locals 5

    .prologue
    .line 365
    new-instance v2, Ljava/util/ArrayList;

    invoke-direct {v2}, Ljava/util/ArrayList;-><init>()V

    .line 368
    .local v2, expiredTimeouts:Ljava/util/List;,"Ljava/util/List<Lorg/jboss/netty/util/HashedWheelTimer$HashedWheelTimeout;>;"
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v3

    iput-wide v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->startTime:J

    .line 369
    const-wide/16 v3, 0x1

    iput-wide v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->tick:J

    .line 371
    :cond_0
    :goto_0
    iget-object v3, p0, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->this$0:Lorg/jboss/netty/util/HashedWheelTimer;

    iget-object v3, v3, Lorg/jboss/netty/util/HashedWheelTimer;->shutdown:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v3}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v3

    if-nez v3, :cond_1

    .line 372
    invoke-direct {p0}, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->waitForNextTick()J

    move-result-wide v0

    .line 373
    .local v0, deadline:J
    const-wide/16 v3, 0x0

    cmp-long v3, v0, v3

    if-lez v3, :cond_0

    .line 374
    invoke-direct {p0, v2, v0, v1}, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->fetchExpiredTimeouts(Ljava/util/List;J)V

    .line 375
    invoke-direct {p0, v2}, Lorg/jboss/netty/util/HashedWheelTimer$Worker;->notifyExpiredTimeouts(Ljava/util/List;)V

    goto :goto_0

    .line 378
    .end local v0           #deadline:J
    :cond_1
    return-void
.end method
